package dji.ux.ext.widget.gimbal;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import dji.common.bus.UXSDKEventBus;
import dji.thirdparty.rx.subscriptions.CompositeSubscription;
import dji.ux.beta.R;
import dji.ux.beta.base.ConstraintLayoutWidget;
import dji.ux.ext.base.UXEEvents;

public class ThermalTemperatureWidget extends ConstraintLayoutWidget {

    private TextView tvTemperature;
    private CompositeSubscription subscription = new CompositeSubscription();

    public ThermalTemperatureWidget(@NonNull Context context) {
        super(context);
    }

    public ThermalTemperatureWidget(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ThermalTemperatureWidget(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        View view = inflate(context, R.layout.ext_widget_thermal_temperature, this);
        tvTemperature = view.findViewById(R.id.tv_temperature);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        this.subscription.add(UXSDKEventBus.getInstance().
                register(UXEEvents.MeterAreaText.class)
                .observeOn(dji.thirdparty.rx.android.schedulers.AndroidSchedulers.mainThread())
                .subscribe(item -> {
                    if (item.isShow()){
                        setVisibility(VISIBLE);
                    }else {
                        setVisibility(GONE);
                    }

                    tvTemperature.setText(item.getText());
                }));
    }

    @Override
    protected void reactToModelChanges() {

    }

    @NonNull
    @Override
    public String getIdealDimensionRatioString() {
        return null;
    }
}
